<template lang="jade">
div.return-bar
	i.iconfont(@click="backTo()") &#xe668;
	div.limitedname 做任务 领红包,何止千元!
	span.top_right_btn(@click="showPop")

div.homepage
	toast(:show.sync="show_dialog") 复制成功


div.promotion.detail_top
	alert.custom_alert(:show.sync="toast_show", title="提示", button-text="确定") {{msg}}
	div.p170711
		div.banner
			img(src="../../assets/images/promotion/170711/pro-170711-banner.png")
		div
			img(src="../../assets/images/promotion/170711/pro-170711-title-1.png")

		ul.clearfix
			li.a5
				span.note 剩余次数:{{items[1]}}次
				a.btn( v-bind:class="{ 'active': items[1]>0 }" , @click="submit('1', items[1]) " )
					img(src="../../assets/images/promotion/170711/pro-170711-btn.png")
				img(src="../../assets/images/promotion/170711/pro-170711-item-5.png")
			li.a10
				span.note 剩余次数:{{items[2]}}次
				a.btn( v-bind:class="{ 'active': items[2]>0 }" , @click="submit('2', items[2]) "  )
					img(src="../../assets/images/promotion/170711/pro-170711-btn.png")
				img(src="../../assets/images/promotion/170711/pro-170711-item-5.png")
			li.a100
				span.note 剩余次数:{{items[3]}}次
				a.btn( v-bind:class="{ 'active': items[3]>0 }"  , @click="submit('3', items[3]) " )
					img(src="../../assets/images/promotion/170711/pro-170711-btn.png")
				img(src="../../assets/images/promotion/170711/pro-170711-item-5.png")
			li.a200
				span.note 剩余次数:{{items[4]}}次
				a.btn( v-bind:class="{ 'active': items[4]>0 }" , @click="submit('4', items[4]) "  )
					img(src="../../assets/images/promotion/170711/pro-170711-btn.png")
				img(src="../../assets/images/promotion/170711/pro-170711-item-5.png")
			li.a500
				span.note 剩余次数:{{items[5]}}次
				a.btn( v-bind:class="{ 'active': items[5]>0 }"  , @click="submit('5', items[5]) " )
					img(src="../../assets/images/promotion/170711/pro-170711-btn.png")
				img(src="../../assets/images/promotion/170711/pro-170711-item-5.png")
			li.a1000
				span.note 剩余次数:{{items[6]}}次
				a.btn( v-bind:class="{ 'active': items[6]>0 }"  , @click="submit('6', items[6]) " )
					img(src="../../assets/images/promotion/170711/pro-170711-btn.png")
				img(src="../../assets/images/promotion/170711/pro-170711-item-5.png")

		div
			img(src="../../assets/images/promotion/170711/pro-170711-step.png")

		div.share(v-show="items['u_code']")
			textarea.copyLink(id="sharelink", type="text") {{bindshare}}
			div.note
				请点击右上角分享
				b 赚取红包
				br
				span 或复制此链接分享给朋友!

			//input(type="button", id="forLoadSwf", value="复制链接", @click=" copyLink ")
			img(src="../../assets/images/promotion/170711/share-box.png")

		div(style="margin-top:1rem;")
			img(src="../../assets/images/promotion/170711/pro-170711-note.png")
</template>


<script>
import '../../assets/sass/promotion.scss'
import {Toast, Alert} from 'vux'
import {c_promotion_info, c_promotion_click} from '../../config/api'

export default {

  data () {
    return {
    	toast_show:false,
    	msg:'',
    	show_dialog:false,
    	items:[],
    	busy:false,
    	bindshare:'',
    	wx_share:{"newsID":"", "title":'', "link":'', "img":'', "desc":''}
    }
  },
  components: {
  	Alert,
    Toast,
  },
  methods: {

    backTo(){
      this.$route.router.go('/')
      //window.history.back();
    },
    submit(type, key){
    	if(key==0) return;
    	if(this.busy) return;

    	if(type=='6'){
    		this.msg = '领取现金1000元,请联系客服,谢谢合作!';
    		this.toast_show =true;
    		return;
    	}

    	this.busy = true;
    	this.$store.dispatch('setShowLoading', true);
    	var data = {'type':type}
		this.$http.post(c_promotion_click, data,'').then(function(rep){
			var rs = rep.data;
			this.busy = false;

    		this.msg = rs.msg;
    		this.toast_show =true;

			this.items = [];
			this.$store.dispatch('setShowLoading', false);
			this.fetch();
      	});
    },

    copyLink(event){
		event.preventDefault();
		// 选取input元素的内容
		var input = document.getElementById("sharelink");
		input.select();
		// 将选区内容复制到剪贴板
		document.execCommand("copy");
		this.show_dialog = true;
    },

	fetch(){
		var that = this
		this.$store.dispatch('setShowLoading', true);

		this.$http({url:c_promotion_info, methods:'GET'}).then(function(rep){
			this.items = rep.data
			this.$store.dispatch('setShowLoading', false);
			if(this.items['u_code']){
				this.bindshare = 'http://m.uximoney.com/?#!/reg?recommend_uid='+this.items['u_code'];

				this.wx_share.title = "送您568元有喜财富现金红包!"
				this.wx_share.desc = "100元起投，资金银行存管，年化收益高达13.2%!"
				this.wx_share.img = 'http://www.uximoney.com/themes/blue/img/promotion/170711/pro-170711-banner.png';
				this.wx_share.link = 'http://m.uximoney.com/?#!/reg?recommend_uid='+this.items['u_code'];
				this.global.wxset(this.wx_share)
			}

		}, function (res) {
			if(res.status==408 || res.ok==false){
				this.fetch();
			}else{
				console.log(res)
			}
		});
	}

  },
  route: {
    activate ( transition ) {
    	this.fetch();
    	transition.next();
    }
  }
}
</script>
